package junitTests;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;

public class SingleUpdateTest extends SeleneseTestCase {
	@Before
	public void setUp() throws Exception {
		selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://localhost:8888/");
		selenium.start();
	}

	@Test
	public void testUpdateVideo() throws Exception {
		selenium.open("/login.jsp");
		assertEquals("Login | Media Vault", selenium.getTitle());
		selenium.type("id=username", "test@gmail.com");
		selenium.type("id=password", "test");
		selenium.click("id=login");
		selenium.waitForCondition("selenium.browserbot.getCurrentWindow().document.getElementById('loginMsgPanel')", "10000");
		assertTrue(selenium.isTextPresent("Your have succesfully logged into Media Vault."));
		selenium.click("link=Continue");
		selenium.waitForPageToLoad("30000");
		assertEquals("Home | Media Vault", selenium.getTitle());
		selenium.click("//div[@id='rp_list']/ul/li[2]/div[3]/a/span");
		selenium.waitForPageToLoad("30000");
		selenium.click("//div[@id='preview_file']/div[3]/a[3]/img");
		selenium.click("id=collectionID");
		selenium.type("id=genreID", "Action");
		selenium.click("id=yearID");
		selenium.type("id=yearID", "2009");
		selenium.type("id=collectionID", "FTV");
		selenium.click("name=btnUpdate");
		selenium.waitForPageToLoad("30000");
		verifyTrue(selenium.isTextPresent("Action"));
	}
	
	@Test
	public void testUpdatePicture() throws Exception {
		selenium.open("/login.jsp");
		assertEquals("Login | Media Vault", selenium.getTitle());
		selenium.type("id=username", "test@gmail.com");
		selenium.type("id=password", "test");
		selenium.click("id=login");
		selenium.waitForCondition("selenium.browserbot.getCurrentWindow().document.getElementById('loginMsgPanel')", "10000");
		assertTrue(selenium.isTextPresent("Your have succesfully logged into Media Vault."));
		selenium.click("link=Continue");
		selenium.waitForPageToLoad("30000");
		assertEquals("Home | Media Vault", selenium.getTitle());
		selenium.click("//div[@id='rp_list']/ul/li[2]/div[4]/a/span");
		selenium.waitForPageToLoad("30000");
		selenium.click("//div[@id='preview_file']/div[3]/a[3]/img");
		selenium.type("id=albumID", "Flowers");
		selenium.click("name=btnUpdate");
		selenium.waitForPageToLoad("30000");
		verifyTrue(selenium.isTextPresent("Flowers"));
	}
	
	@Test
	public void testUpdateAudio() throws Exception {
		selenium.open("/login.jsp");
		assertEquals("Login | Media Vault", selenium.getTitle());
		selenium.type("id=username", "test@gmail.com");
		selenium.type("id=password", "test");
		selenium.click("id=login");
		selenium.waitForCondition("selenium.browserbot.getCurrentWindow().document.getElementById('loginMsgPanel')", "10000");
		assertTrue(selenium.isTextPresent("Your have succesfully logged into Media Vault."));
		selenium.click("link=Continue");
		selenium.waitForPageToLoad("30000");
		assertEquals("Home | Media Vault", selenium.getTitle());
		selenium.click("//div[@id='rp_list']/ul/li[2]/div[2]/a/span");
		selenium.waitForPageToLoad("30000");
		selenium.click("//div[@id='preview_file']/div[3]/a[3]/img");
		selenium.click("id=artistID");
		selenium.type("id=artistID", "The Killers");
		selenium.click("name=btnUpdate");
		selenium.waitForPageToLoad("30000");
		verifyTrue(selenium.isTextPresent("The Killers"));

	}
	
	@Test
	public void testUpdateDocument() throws Exception {
		selenium.open("/login.jsp");
		assertEquals("Login | Media Vault", selenium.getTitle());
		selenium.type("id=username", "test@gmail.com");
		selenium.type("id=password", "test");
		selenium.click("id=login");
		assertTrue(selenium.isTextPresent("Your have succesfully logged into Media Vault."));
		selenium.waitForCondition("selenium.browserbot.getCurrentWindow().document.getElementById('loginMsgPanel')", "10000");
		selenium.click("link=Continue");
		selenium.waitForPageToLoad("30000");
		assertEquals("Home | Media Vault", selenium.getTitle());
		selenium.click("//div[@id='rp_list']/ul/li[2]/div[5]/a/span");
		selenium.waitForPageToLoad("30000");
		selenium.click("//div[@id='preview_file']/div[3]/a[3]/img");
		selenium.click("id=albumID");
		selenium.type("id=albumID", "QUT");
		selenium.click("name=btnUpdate");
		selenium.waitForPageToLoad("30000");
		verifyTrue(selenium.isTextPresent("QUT"));
	}

	@After
	public void tearDown() throws Exception {
		selenium.stop();
	}
}
